import sys
from PySide6.QtWidgets import QApplication, QDialog, QPushButton, QVBoxLayout


class MyDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.initUI()

    def initUI(self):
        self.setWindowTitle("示例对话框")
        layout = QVBoxLayout()
        self.button = QPushButton("关闭对话框", self)
        self.button.clicked.connect(self.close)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def showEvent(self, event):
        super().showEvent(event)
        print("对话框显示")

    def hideEvent(self, event):
        super().hideEvent(event)
        print("对话框隐藏")


app = QApplication(sys.argv)
dialog = MyDialog()
dialog.show()
sys.exit(app.exec())